package cn.edu.sdjzu.xg.eagle.bysj.controller;

import cn.edu.sdjzu.xg.eagle.bysj.annotation.IgnoreAuth;
import cn.edu.sdjzu.xg.eagle.bysj.annotation.SysLog;
import cn.edu.sdjzu.xg.eagle.bysj.entity.TongzhigonggaoEntity;
import cn.edu.sdjzu.xg.eagle.bysj.entity.view.TongzhigonggaoView;
import cn.edu.sdjzu.xg.eagle.bysj.service.Interface.TongzhigonggaoService;
import cn.edu.sdjzu.xg.eagle.bysj.utils.MPUtil;
import cn.edu.sdjzu.xg.eagle.bysj.utils.PageUtils;
import cn.edu.sdjzu.xg.eagle.bysj.utils.R;
import com.baomidou.mybatisplus.mapper.EntityWrapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.Date;
import java.util.Map;

/**
 * 通知公告
 * 后端接口
 * @author 
 * @email 
 * @date 2025-06-02 13:29:27
 */
@RestController
@RequestMapping("/tongzhigonggao")
public class TongzhigonggaoController {
    @Autowired
    private TongzhigonggaoService tongzhigonggaoService;
    /**
     * 后台列表
     */
    @RequestMapping("/page")
    public R page(@RequestParam Map<String, Object> params, TongzhigonggaoEntity tongzhigonggao,
                  @RequestParam(required = false) @DateTimeFormat(pattern="yyyy-MM-dd") Date fabushijianStart,
                  @RequestParam(required = false) @DateTimeFormat(pattern="yyyy-MM-dd") Date fabushijianEnd,
                  HttpServletRequest request){
                                    EntityWrapper<TongzhigonggaoEntity> ew = new EntityWrapper<TongzhigonggaoEntity>();
                                                                                                                                                                    if(fabushijianStart!=null) ew.ge("fabushijian", fabushijianStart);
                    if(fabushijianEnd!=null) ew.le("fabushijian", fabushijianEnd);
                                    
        
        
        PageUtils page = tongzhigonggaoService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, tongzhigonggao), params), params));
        return R.ok().put("data", page);
    }
    /**
     * 前端列表
     */
	@IgnoreAuth
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params,TongzhigonggaoEntity tongzhigonggao,
                @RequestParam(required = false) @DateTimeFormat(pattern="yyyy-MM-dd") Date fabushijianStart,
                @RequestParam(required = false) @DateTimeFormat(pattern="yyyy-MM-dd") Date fabushijianEnd,
		HttpServletRequest request){
        EntityWrapper<TongzhigonggaoEntity> ew = new EntityWrapper<TongzhigonggaoEntity>();
                if(fabushijianStart!=null) ew.ge("fabushijian", fabushijianStart);
                if(fabushijianEnd!=null) ew.le("fabushijian", fabushijianEnd);

		PageUtils page = tongzhigonggaoService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, tongzhigonggao), params), params));
        return R.ok().put("data", page);
    }
	/**
     * 列表
     */
    @RequestMapping("/lists")
    public R list( TongzhigonggaoEntity tongzhigonggao){
       	EntityWrapper<TongzhigonggaoEntity> ew = new EntityWrapper<TongzhigonggaoEntity>();
      	ew.allEq(MPUtil.allEQMapPre( tongzhigonggao, MPUtil.camelToSnake("tongzhigonggao")));
        return R.ok().put("data", tongzhigonggaoService.selectListView(ew));
    }
	 /**
     * 查询
     */
    @RequestMapping("/query")
    public R query(TongzhigonggaoEntity tongzhigonggao){
        EntityWrapper< TongzhigonggaoEntity> ew = new EntityWrapper< TongzhigonggaoEntity>();
 		ew.allEq(MPUtil.allEQMapPre( tongzhigonggao, MPUtil.camelToSnake("tongzhigonggao")));
		TongzhigonggaoView tongzhigonggaoView =  tongzhigonggaoService.selectView(ew);
		return R.ok("查询通知公告成功").put("data", tongzhigonggaoView);
    }
    /**
     * 后端详情
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
        TongzhigonggaoEntity tongzhigonggao = tongzhigonggaoService.selectById(id);
		tongzhigonggao = tongzhigonggaoService.selectView(new EntityWrapper<TongzhigonggaoEntity>().eq("id", id));
        return R.ok().put("data", tongzhigonggao);
    }
    /**
     * 前端详情
     */
	@IgnoreAuth
    @RequestMapping("/detail/{id}")
    public R detail(@PathVariable("id") Long id){
        TongzhigonggaoEntity tongzhigonggao = tongzhigonggaoService.selectById(id);
		tongzhigonggao = tongzhigonggaoService.selectView(new EntityWrapper<TongzhigonggaoEntity>().eq("id", id));
        return R.ok().put("data", tongzhigonggao);
    }
    /**
     * 后端保存
     */
    @RequestMapping("/save")
    @SysLog("新增通知公告")
    public R save(@RequestBody TongzhigonggaoEntity tongzhigonggao, HttpServletRequest request){
    	//ValidatorUtils.validateEntity(tongzhigonggao);
        tongzhigonggaoService.insert(tongzhigonggao);
        return R.ok();
    }
    /**
     * 前端保存
     */
    @SysLog("新增通知公告")
    @RequestMapping("/add")
    public R add(@RequestBody TongzhigonggaoEntity tongzhigonggao, HttpServletRequest request){
    	//ValidatorUtils.validateEntity(tongzhigonggao);
        tongzhigonggaoService.insert(tongzhigonggao);
        return R.ok();
    }
    /**
     * 修改
     */
    @RequestMapping("/update")
    @Transactional
    @SysLog("修改通知公告")
    public R update(@RequestBody TongzhigonggaoEntity tongzhigonggao, HttpServletRequest request){
        //ValidatorUtils.validateEntity(tongzhigonggao);
        tongzhigonggaoService.updateById(tongzhigonggao);//全部更新
        return R.ok();
    }
    /**
     * 删除
     */
    @RequestMapping("/delete")
    @SysLog("删除通知公告")
    public R delete(@RequestBody Long[] ids){
        tongzhigonggaoService.deleteBatchIds(Arrays.asList(ids));
        return R.ok();
    }
}
